﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ChimneySim
{
    class Room
    {
        public BoundingBox roomLeft, roomRight, roomRight2, roomFront, roomBack, roomTop;
        public BoundingBox roomAll;
        MainForm form;
        private float temp0, temp1;
        private World world;

        public Room(MainForm form, World world)
        {
            this.form = form;
            this.world = world;
            Refresh();
        }

        public void Refresh()
        {
            this.temp0 = (float)form.roomTemp0NB.Value;
            this.temp1 = (float)form.roomTemp1NB.Value;

            this.roomAll = new BoundingBox(new Vector3(roomLeft.Min.X, roomLeft.Min.Y, roomRight.Max.Z),  new Vector3(roomRight.Max.X, roomRight.Max.Y, roomLeft.Min.Z));//roomLeft.Min, roomRight.Max);
        }

        public float TemperatureOnHeight(float height)
        {
            return (temp1 - temp0) / roomLeft.Max.Y * height + temp0;
        }

        public float RoOnHeight(float height)
        {
            Refresh();
            return world.pressure / ((float)8.3144 * TemperatureOnHeight(height));
        }

        public float ActivePressureOnHeight(float height)
        {
            Refresh();
            return (RoOnHeight(roomLeft.Max.Y) - RoOnHeight(height)) * roomLeft.Max.Y * world.gravity;
        }

        public float ActiveForceOnHeight(float height)
        {
            Refresh();
            float S = Math.Abs(roomRight.Min.X - roomLeft.Max.X) * Math.Abs(roomLeft.Max.Z - roomRight.Min.Z);

            return ActivePressureOnHeight(height);// *S;
        }
    }
}
